package com.corgi.test.cglib.copier.convert;

import net.sf.cglib.core.Converter;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * AccountConverter
 *
 * @title: AccountConverter
 * @description:
 * @author: dengmiao
 * @create: 2019-12-21 09:57
 **/
public class AccountConverter implements Converter {

    private final static String FORMAT_LOCAL_DATE="yyyy-MM-dd";

    @Override
    public Object convert(Object source, Class target, Object context) {
        if (source instanceof Integer) {
            return (Integer) source;
        } else if (source instanceof LocalDate) {
            LocalDate date = (LocalDate) source;
            return date.format(DateTimeFormatter.ofPattern(FORMAT_LOCAL_DATE));
        } else if (source instanceof BigDecimal) {
            BigDecimal bd = (BigDecimal) source;
            return bd.toPlainString();
        }
        return null;
    }
}
